package com.netease.nie.service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.common.CommonService;
import com.netease.nie.dao.GoodsInfoDao;
import com.netease.nie.dto.GoodsInfoDto;
import com.netease.nie.model.GoodsInfo;

/**
 * 
 * @author wwbn3695
 * @createDate May 31st,2016
 *
 */
@Service
public class GoodsInfoServiceImpl extends CommonService implements GoodsInfoService {

	@Autowired
	private GoodsInfoDao goodsInfoDao;

	public GoodsInfoDto queryGoodsInfoById(int id) {
		GoodsInfoDto goodsInfoDto = new GoodsInfoDto();
		GoodsInfo goodsInfo = goodsInfoDao.queryGoodsInfoById(id);
		CopyUtils.copy(goodsInfoDto, goodsInfo);
		return goodsInfoDto;
	}
	
	public Map<Integer, GoodsInfo> queryGoodsInfoByIds(List<Integer> ids) {
		if (ids.isEmpty()) 
			return Collections.emptyMap();
		
		List<GoodsInfo> goodsInfoList = goodsInfoDao.queryGoodsInfoListByIds(ids);
		
		if (goodsInfoList == null || goodsInfoList.isEmpty())
			return Collections.emptyMap();
		
		Map<Integer, GoodsInfo> goodsInfoMap = new HashMap<>();
		
		int size = goodsInfoList.size();
		int goodsId;
		GoodsInfo goodsInfo = null;
		
		for (int i = 0; i < size; ++i) {
			goodsInfo = goodsInfoList.get(i);
			goodsId = goodsInfo.getId();
			goodsInfoMap.put(goodsId, goodsInfo);
		}
		
		return goodsInfoMap;
	}
	
}
